{extend name="base" /}
{block name="title"}订单确认{/block}
{block name="head"}
<style>
input.weui-pay-inputs{background-color:#fff;}
</style>
{/block}
{block name="body"}
<div class="weui-pay ms-controller" ms-controller="cash">
  <div class="weui-pay-inner">
    <h1 class="weui-pay-title">提现金额(元)</h1>
    <div class="weui-pay-input">
      <strong class="weui-pay-strong" style="top:8px">￥</strong>
      <input type="number" class="weui-pay-inputs" placeholder="请输入金额" ms-duplex-number="@cashNow" disabled />
    </div>
    <div class="weui-pay-intro">提现到零钱, 最低<span class="f-red">{{@cashMin}}</span>元, 当前余额 <span class="f-red">{{@mRebate|currency}}</span></div>
  </div>
  <div class="weui-pay-btn">
    <a ms-class="['weui_btn','weui_btn_primary',(@cashNow<=0||@cashNow>@mRebate||@cashNow<@cashMin)&&'weui_btn_disabled']" ms-on-tap="@tapCash">立即提现</a>
  </div>
</div>
{/block}
{block name="foot"}
<script>
avalon.ready(function () {
  var vm = avalon.define({
    $id: "cash",
    mRebate: "{$Agent.mRebate??0}" * 1, // 我的当前佣金
    cashNow: "{$Agent.mRebate??0}" * 1, // 欲提现金额
    cashMin: "{$CashMin??0}", // 单次提现最低额
    tapCash: function () {
      avalon.log({cashMin:this.cashMin,mRebate:this.mRebate,cashNow:this.cashNow});
      if (this.cashNow <= 0 || this.cashNow > this.mRebate || this.cashNow < this.cashMin) {
        return;
      }
      $.req({
        type: 'POST',
        url: "{:url('cash')}",
        data: {
          money: this.cashNow
        },
        success: function (resp, status, xhr) {
          avalon.log(resp);
          $.alert(resp.error, function () {
            if (resp.errno == 0) {
              history.back();
            }
          });
        }
      });
    }
  });
  avalon.scan(document.body);
});
</script>
{/block}